package com.example.bailin.giftsay.main.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.example.bailin.giftsay.R;
import com.example.bailin.giftsay.guide.PopupClick;
import com.example.bailin.giftsay.tool.MyApp;

/**
 * Created by bailin on 16/8/30.
 */
public class PxAdapter extends BaseAdapter {
    private String [] strings = {"默认排序", "按热度排序", "价格从低到高", "价格从高到低"};
    private String [] strings1 = {"默认排序", "按热度排序"};
    private PopupClick popupClick;
    private int index;
    private int type;

    public void setType(int type) {
        this.type = type;
        notifyDataSetChanged();
    }

    public void setIndex(int index) {
        this.index = index;
        notifyDataSetChanged();
    }

    public void setPopupClick(PopupClick popupClick) {
        this.popupClick = popupClick;
    }

    @Override
    public int getCount() {
        if (type == 1) {
            return strings1.length;
        }
        return strings.length;

    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        convertView = LayoutInflater.from(MyApp.getContext()).inflate(R.layout.item_paixu, parent, false);
        TextView tv = (TextView) convertView.findViewById(R.id.tv_paixu);
        ImageView iv = (ImageView) convertView.findViewById(R.id.iv_check);
        RelativeLayout Rl = (RelativeLayout) convertView.findViewById(R.id.ll_paixu);
        tv.setText(strings[position]);

        Rl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                popupClick.itemOnClick(position);
            }
        });
        if (index == position) {
            iv.setVisibility(View.VISIBLE);
        } else {
            iv.setVisibility(View.GONE);
        }
        return convertView;
    }
}
